package com.molichuxing.gateway.bff.basic.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.molichuxing.framework.contants.RedisKeyConst;
import com.molichuxing.framework.utils.RedisUtil;
import com.molichuxing.gateway.bff.basic.convertor.Convert;
import com.molichuxing.gateway.bff.basic.entity.response.ReceiptCompanyVo;
import com.molichuxing.gateway.bff.basic.service.ReceiptCompanyBffService;
import com.molichuxing.services.infrastructure.dto.response.ReceiptCompanyDto;
import com.molichuxing.services.infrastructure.service.ReceiptCompanyService;

@Service("receiptCompanyBffService")
public class ReceiptCompanyBffServiceImpl implements ReceiptCompanyBffService {
	private static final Logger logger = LoggerFactory.getLogger(ReceiptCompanyBffServiceImpl.class);

	@Resource
	private RedisUtil redisUtil;

	@Resource
	private ReceiptCompanyService receiptCompanyService;

	/**
	 * 获取所有收款公司信息
	 * 
	 * @return
	 */
	@Override
	public List<ReceiptCompanyVo> getReceiptCompany() {
		List<ReceiptCompanyVo> result = null;
		// 查询redis
		String companys = redisUtil.get(RedisKeyConst.RECEIPT_COMPANY);
		if (companys != null) {
			return JSONObject.parseObject(companys, List.class);
		}
		// 不存在，查询
		List<ReceiptCompanyDto> receiptCompanyDtos = receiptCompanyService.getReceiptCompany();
		result = Convert.toReceiptCompanyVo(receiptCompanyDtos);
		// 保存进redis
		redisUtil.set(RedisKeyConst.RECEIPT_COMPANY, JSONObject.toJSONString(result));

		return result;
	}
}
